﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：徐彦龙 
    //
    // 文件名：RoleList.cs
    // 文件功能描述：主用户注册
    // 创建标识：徐彦龙2009-03-10
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using System.Collections.Generic;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class UserRegister : BasePage
    {
        public string id;
        public string name;
        public string strRoleID;

        public UserRegister()
        {
            this.ModuleNo = Module.系统管理.ToString();
            this.PageOperateType = OperateType.主用户管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //医疗机构
                strRoleID = this.ddlRoleList.SelectedValue;
                IBLL_Hospital ih = Factory.BLL_Hospital();
                IList<Hospital> lhp = ih.GetAllUnregHospital();
                this.CreateViewToHospital();
                this.gvwUnRegisterList.DataSource = lhp;
                this.gvwUnRegisterList.DataBind();
            }
        }
        /// <summary>
        /// 动态生成未注册企业列表
        /// </summary>
        public void CreateViewToCompany()
        {
            BoundField dc1 = new BoundField();
            dc1.DataField = "CompanyID";
            dc1.HeaderText = "企业编号";
            dc1.Visible = true;

            BoundField dc2 = new BoundField();
            dc2.Visible = true;
            dc2.DataField = "CompanyName";
            dc2.HeaderText = "企业名称";


            HyperLinkField hl = new HyperLinkField();
            hl.HeaderText = "操作";
            hl.Text = "主用户注册";
            string[] pram2 = { "CompanyID" };
            hl.DataNavigateUrlFields = pram2;
            hl.DataNavigateUrlFormatString = "UserAdd.aspx?id={0}&roleID=" + strRoleID;
            hl.DataTextField = "";

            this.gvwUnRegisterList.Columns.Add(dc1);
            this.gvwUnRegisterList.Columns.Add(dc2);
            this.gvwUnRegisterList.Columns.Add(hl);

        }

        /// <summary>
        /// 动态生成未注册医疗机构的列表
        /// </summary>
        public void CreateViewToHospital()
        {

            BoundField dc1 = new BoundField();
            dc1.DataField = "HospitalID";
            dc1.HeaderText = "医疗机构编号";
            dc1.Visible = true;

            BoundField dc2 = new BoundField();
            dc2.Visible = true;
            dc2.DataField = "HospitalName";
            dc2.HeaderText = "医疗机构名称";


            HyperLinkField hl = new HyperLinkField();
            hl.HeaderText = "操作";
            hl.Text = "主用户注册";
            string[] pram2 = { "HospitalID" };
            hl.DataNavigateUrlFields = pram2;
            hl.DataNavigateUrlFormatString = "UserAdd.aspx?id={0}&roleID=" + strRoleID;
            hl.DataTextField = "";

            this.gvwUnRegisterList.Columns.Add(dc1);
            this.gvwUnRegisterList.Columns.Add(dc2);
            this.gvwUnRegisterList.Columns.Add(hl);

        }

        /// <summary>
        /// 动态生成未注册管理机构的列表
        /// </summary>
        public void CreateViewToManage()
        {
            BoundField dc1 = new BoundField();
            dc1.DataField = "ManageOrgID";
            dc1.HeaderText = "管理机构编号";
            dc1.Visible = true;

            BoundField dc2 = new BoundField();
            dc2.Visible = true;
            dc2.DataField = "ManageOrgName";
            dc2.HeaderText = "管理机构名称";


            HyperLinkField hl = new HyperLinkField();
            hl.HeaderText = "操作";
            hl.Text = "主用户注册";
            string[] pram2 = { "ManageOrgID" };
            hl.DataNavigateUrlFields = pram2;
            hl.DataNavigateUrlFormatString = "UserAdd.aspx?id={0}&roleID=" + strRoleID;
            hl.DataTextField = "";

            this.gvwUnRegisterList.Columns.Add(dc1);
            this.gvwUnRegisterList.Columns.Add(dc2);
            this.gvwUnRegisterList.Columns.Add(hl);

        }

        ///// <summary>
        ///// 绑定所有角色到下拉列表框，并绑定相应的未注册机构到列表
        ///// </summary>
        //private void SetBind()
        //{
        //    IBLL_Role ib = Factory.BLL_Role();
        //    IList<Role> lc = ib.GetAllRole();
        //    this.ddlRoleList.DataSource = lc;
        //    this.ddlRoleList.DataTextField = "RoleName";
        //    this.ddlRoleList.DataValueField = "RoleId";
        //    this.ddlRoleList.DataBind();

        //    strRoleID = this.ddlRoleList.SelectedValue;
        //    if (strRoleID == "02")
        //    {
        //        //配送企业
        //        IBLL_Company ic = Factory.BLL_Company();
        //        IList<Company> lcp =ic.GetAllUnregCompany();
        //        this.CreateViewToCompany();
        //        this.gvwUnRegisterList.DataSource = lcp;
        //        this.gvwUnRegisterList.DataBind();
        //    }
        //    else if (strRoleID == "01")
        //    {
        //        //医疗机构
        //        IBLL_Hospital ih = Factory.BLL_Hospital();
        //        IList<Hospital> lhp = ih.GetAllUnregHospital();
        //        this.CreateViewToHospital();
        //        this.gvwUnRegisterList.DataSource = lhp;
        //        this.gvwUnRegisterList.DataBind();
        //    }
        //    else if(strRoleID=="03")
        //    {
        //        //中心机构
        //        IBLL_ManageOrg im = Factory.BLL_ManageOrg();
        //        IList<ManageOrg> lmp = im.GetAllUnregManageOrg();
        //        this.CreateViewToManage();
        //        this.gvwUnRegisterList.DataSource = lmp;
        //        this.gvwUnRegisterList.DataBind();
        //    }
        //}

        /// <summary>
        /// 根据下拉列表框选择的内容不同显示不同的内容带gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlRoleList_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvwUnRegisterList.Columns.Clear();
            strRoleID = this.ddlRoleList.SelectedValue;
            if (strRoleID == "02" || strRoleID == "05")
            {
                //配送企业
                IBLL_Company ic = Factory.BLL_Company();
                //IList<Company> lcp = ic.GetAllUnregCompany();
                IList<Company> lcp = ic.GetAllUnregCompany(strRoleID == "02"?false:true);
                this.CreateViewToCompany();
                this.gvwUnRegisterList.DataSource = lcp;
                this.gvwUnRegisterList.DataBind();
            }
            else if (strRoleID == "03")
            {
                //经办机构、监督机构等
                IBLL_ManageOrg im = Factory.BLL_ManageOrg();
                IList<ManageOrg> lmp = im.GetAllUnregManageOrg();
                this.CreateViewToManage();
                this.gvwUnRegisterList.DataSource = lmp;
                this.gvwUnRegisterList.DataBind();
            }
            else if (strRoleID == "01")
            {
                //医疗机构
                IBLL_Hospital ih = Factory.BLL_Hospital();
                IList<Hospital> lhp = ih.GetAllUnregHospital();
                this.CreateViewToHospital();
                this.gvwUnRegisterList.DataSource = lhp;
                this.gvwUnRegisterList.DataBind();
            }
        }
    }
}
